<?php
class shop_sqsitesControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
	}
	
	public function onInit(){
		
	}
	
	public function onDefault(){
		$sitearea=M("options")->select(array(
			"where"=>" status=1 AND tablename='sitearea' AND pid=0 ",
			"order"=>" orderindex asc ,id asc"
		));
		$siteids=M("shop_sqsites")->selectCols(array(
			"where"=>"shopid=".SHOPID,
			"fields"=>"siteid"
		));
	 
		if($sitearea){
			foreach($sitearea as $k=>$v){
				$ids=M("options")->id_family($v['id']);
			 
				$v['sites']=M("sites")->getListBycityidIds($ids);
				if($siteids && $v['sites']){
					foreach($siteids as $siteid){
						if(isset($v['sites'][$siteid])){
							$v['sites'][$siteid]['issq']=1;
						}
					}
				}
				$sitearea[$k]=$v;
			}
		}
	
		$this->smarty->assign(array(
			"sitearea"=>$sitearea,
 
		));
		$this->smarty->display("shop_sqsites/index.html");
	}
	
	public function onSave(){
		$siteid=get('siteid','i');
		$row=M("shop_sqsites")->selectRow("shopid=".SHOPID." AND siteid=".$siteid."");
		if($row){
			M("shop_sqsites")->delete("id=".$row['id']);
				$this->goAll("取消成功",0,11);
		}else{
			M("shop_sqsites")->insert(array(
				"shopid"=>SHOPID,
				"siteid"=>$siteid
			));
			$this->goAll("添加成功",0,1);
		}
	
	}
	
}
?>